﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using DB;
using System.Globalization;

namespace Control
{
    public class BookingController
    {
        private IDbBooking dbBooking;
        private IDbShow dbShow;
        private IDbSeat dbSeat;
        public BookingController()
        {
            dbBooking = new DbBooking();
            dbShow = new DbShow();
            dbSeat = new DbSeat();
        }

        public List<Seat> GetSeatsTaken(Show showObj, bool retriveAssociation)
        {
            return dbSeat.FindSeatsTaken(showObj, retriveAssociation);
        }

        public int CreateBooking(List<string> seatIds, DateTime dtStart, string cName, string phoneNo, int reservation, double pricePrTicket)
        {
            List<Ticket> tickets = new List<Ticket>();

            foreach (string seatId in seatIds)
            {
                Ticket ticketObj = new Ticket();
                Seat seatObj = new Seat();
                seatObj.SeatId = seatId;
                ticketObj.Seat = seatObj;
                tickets.Add(ticketObj);
            }

            CinemaHall cHallObj = new CinemaHall();
            cHallObj.Name = cName;

            Show showObj = new Show();
            showObj.CinemaHall = cHallObj;
            showObj.DateTimeStart = dtStart;


            foreach (Ticket ticketObj in tickets)
            {
                ticketObj.Show = showObj;
                ticketObj.Price = pricePrTicket;
            }

            Customer custObj = new Customer();
            custObj.PhoneNo = phoneNo;


            Booking bookingObj = new Booking();
            bookingObj.Tickets = tickets;
            bookingObj.Show = showObj;
            bookingObj.Customer = custObj;
            bookingObj.Reservation = reservation;

            return dbBooking.InsertBooking(bookingObj);
        }


        public DateTime[] GetDates14days()
        {

            DateTime[] dates = new DateTime[15];
            DateTime dT = DateTime.Now.Date;


            for (int i = 0; i < 15; i++)
            {
                dates[i] = dT;
                dT = dT.AddDays(1);
            }

            //Console.WriteLine(dT.ToString("dd/MM/yyyy"));

            return dates;
        }

        public List<Show> GetShowsForThisDate(DateTime date)
        {
            return dbShow.GetAllShowsThisDate(date, true);
        }

        public List<Booking> FindBookings(string phoneNo)
        {
            return dbBooking.FindBookings(phoneNo, true);
        }

        public int DeleteBooking(Booking bookingObj)
        {
            return dbBooking.DeleteBooking(bookingObj);
        }

    }
}
